package com.itheima.test1;

import java.util.Random;

public class role {
    private String name;
    private int blood;

    public role() {}
    public role(String name, int blood) {
        this.name = name;
        this.blood = blood;
    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getBlood() {
        return blood;
    }
    public void setBlood(int blood) {
        this.blood = blood;
    }

    //定义一个方法用于攻击别人
    //方法的调用者去攻击参数
    public void attack(role role){
        //this表示方法的调用者
        Random r = new Random();
        int hurt = r.nextInt(20)+1;

        int remainBlood = role.getBlood()-hurt;//剩余血量
        //判断剩余血量是否大于零
        remainBlood = remainBlood < 0 ? 0 : remainBlood;
        //修改一下被揍的人的剩余血量
        role.setBlood(remainBlood);

        System.out.println(this.getName()+"举起了拳头攻击了"+role.getName()+"一下，"+
                "造成了"+hurt+"伤害，"+role.getName()+"还剩下"+remainBlood+"点血");
    }
}
